package com.ssy.lingxi.common.constant.member;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 会员类型枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-12
 */
public enum MemberTypeEnum {
    /**
     * 企业会员 - 1
     */
    MERCHANT(1, "企业会员"),

    /**
     * 企业个人会员 - 2
     */
    MERCHANT_PERSONAL(2, "个人会员"),

    /**
     * 渠道会员 - 3
     */
    CHANNEL(3, "渠道企业会员"),

    /**
     * 渠道个人会员 - 4
     */
    CHANNEL_PERSONAL(4, "渠道个人会员");

    private Integer code;

    MemberTypeEnum(Integer code, String message) {
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public static String getMessage(Integer code) {
        return LanguageHolder.getName(MemberTypeEnum.class, code);
    }

    public static String getCodeMessage(Integer code) {
        return LanguageHolder.getName(MemberTypeEnum.class, code);
    }

    public static MemberTypeEnum toEnum(Integer value) {
        return Arrays.stream(MemberTypeEnum.values()).filter(e -> e.getCode().equals(value)).findFirst().orElse(MERCHANT);
    }

    public static List<Integer> toList() {
        return Arrays.stream(MemberTypeEnum.values()).map(MemberTypeEnum::getCode).collect(Collectors.toList());
    }
}
